import java.awt.*;

import javax.swing.*;

public class StatsLayer extends JPanel {
	String statsbar = "statsbar.png";
	Image image;
	Player player;
	Ticker ticks;
	Cursor cursor;

	public StatsLayer(Cursor cursor, Ticker ticks, Player player) {
		this.player=player;
		this.ticks=ticks;
		this.cursor = cursor;
		this.setFocusable(false);

		// Initialize image from the file names
		MediaTracker media = new MediaTracker(this);
		image = Toolkit.getDefaultToolkit().getImage("graphics\\" + statsbar);
		media.addImage(image, 0);
		try {
			media.waitForID(0);
		} catch (Exception e) {
		}
	}

	public void paint(Graphics g) {
		this.setLocation(850, 0);
		this.setSize(150, 550);

		Font font1 = new Font("Arial", Font.BOLD, 15);

		// Draw background
		g.drawImage(image, 0, 0, this);

		g.setColor(Color.white);
		g.setFont(font1);
		String[] status = { "" };
		String[] commands = { "" };

		g.drawString(cursor.gettxtMode(), 40, 53);
		g.drawString("Ticks: "+this.ticks.getTick(), 47, 480);
		g.drawString("Gold: "+player.getGold(), 47, 500);
		g.drawString("Lumber: "+player.getLumber(), 47, 515);
		g.drawString("Food: "+player.getFood(), 47, 530);
		
		try {
			status = cursor.getSelected().gettxtStatus();
			commands = cursor.getSelected().gettxtCommands();
		} catch (Exception e) {
		}
		// Populate the stats table
		for (int i = 0; i < status.length; i++) {
			g.drawString(status[i], 25, 75 + (i * 15));
		}

		int order = cursor.getOrder();
		// Populate the commands table
		for (int i = 0; i < commands.length; i++) {
			if (order == i) {
				g.setColor(Color.yellow);
			}
			g.drawString(commands[i], 25, 275 + (i * 15));
			g.setColor(Color.white);
		}

		g.setColor(Color.black);
		g.drawRect(-1, 0, 150, 549);
	}
}
